using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEditor;
using SgsUI;

namespace SgsUI.Editor
{
    [CustomEditor(typeof(SgsUI.ViewButton))]
    [CanEditMultipleObjects]
    public class ViewButtonEditor : ViewEditorBase
    {
        private List<string> m_key_map = new List<string>
        {
            "button_type","res","normal","pressed","disabled"
        };
        private Dictionary<string,SerializedProperty> m_prop = new Dictionary<string,SerializedProperty>();
        ViewButton m_button;
        protected override void OnEnable()
        {
            base.OnEnable();
            m_button = target as ViewButton;
            foreach(string key in m_key_map)
            {
                m_prop[key] = serializedObject.FindProperty(key);
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            m_button.UpdateButton();

            serializedObject.ApplyModifiedProperties();
 
            serializedObject.Update();
            GUI.enabled = false;

            ButtonRes.Type typeEnum = (ButtonRes.Type)m_prop["button_type"].enumValueIndex;
            if(typeEnum == ButtonRes.Type.Simple_Btn)
            {
                if(m_prop["res"].stringValue != String.Empty)
                {
                    EditorGUILayout.PropertyField(m_prop["res"]);
                }
            }
            else if(typeEnum == ButtonRes.Type.Normal_Btn)
            {
                if(m_prop["normal"].stringValue != String.Empty)
                {
                    EditorGUILayout.PropertyField(m_prop["normal"]);
                }

                if(m_prop["pressed"].stringValue != String.Empty)
                {
                    EditorGUILayout.PropertyField(m_prop["pressed"]);
                }

                if(m_prop["disabled"].stringValue != String.Empty)
                {
                    EditorGUILayout.PropertyField(m_prop["disabled"]);
                }
            }
                
            
            GUI.enabled = true;
        }
    }
}
